package cn.tedu.mimall.product.controller;

import cn.tedu.mimall.product.service.IProductService;
import cn.tedu.mimall.product.pojo.dto.ProductAddNewDTO;
import cn.tedu.mimall.product.pojo.dto.ProductUpdateDTO;
import cn.tedu.mimall.product.web.JsonResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@Slf4j
@Api(tags = "商品业务管理")
@RequestMapping("/products")
public class ProductController {

    @Autowired
    private IProductService productService;

    @PostMapping("/add-new")
    @ApiOperation("添加商品")
    public JsonResult addNew(ProductAddNewDTO productAddNewDTO){
        productService.addNew(productAddNewDTO);
        return JsonResult.ok("添加成功!");
    }

    @PostMapping("/delete")
    @ApiOperation("删除商品数据")
    public JsonResult delete(Long id){
        productService.deleteById(id);
        return JsonResult.ok("删除成功!");
    }

    @PostMapping("/update")
    @ApiOperation("修改商品数据")
    public JsonResult update(Long id, ProductUpdateDTO productUpdateDTO){
        productService.updateInfoById(id, productUpdateDTO);
        return JsonResult.ok("修改成功!");
    }

    @PostMapping("/update/state")
    @ApiOperation("修改商品状态")
    public JsonResult updateState(Long id, Long stateId){
        productService.updateProductStateById(id, stateId);
        return JsonResult.ok("修改商品状态成功!");
    }
}
